import Sequelize from 'sequelize'

// 定义sequelize实例
export const sequelize = new Sequelize({
  dialect: 'sqlite',
  storage: './blog.db'
})

// 同步模型到数据库
export const sync = async () => {
  await sequelize.sync()  //{ force: true }

  // 插入初始数据
  // 动态导入模型
  let { Blog } = await import('../model/Blog.js')
  let blogs = [
    {
      // id: 1,
      title: '今天是星期天',
      author: '张三'
    },
    {
      // id: 2,
      title: '明天是星期一',
      author: '李四'
    },
    {
      // id: 3,
      title: '后天是星期二',
      author: '王五'
    },
  ]
  Blog.bulkCreate(blogs)
}